
$(function(){
    $('#show-popup-btn').click(function(){
        $('#popup-modal').modal('show');
    });
});

function Add_mckQr(){
    var beizhu               = $("#beizhu").val();
    var alipaymck_uid        = $("#alipaymck_uid").val();
    var alipaymck_appid      = $("#alipaymck_appid").val();
    var alipaypublicmck_key  = $("#alipaypublicmck_key").val();
    var appprivatemck_key    = $("#appprivatemck_key").val();
    var ii = layer.load(5, {
		shade: [0.1, '#fff']
	});
	$.ajax({
	    type: "POST",
	    url: "Ajax.php",
	    data: {
	        act:'Add_mckQr',
			alipaymck_uid:alipaymck_uid,
			alipaymck_appid:alipaymck_appid,
			alipaypublicmck_key:alipaypublicmck_key,
			appprivatemck_key:appprivatemck_key,
			beizhu:beizhu
		},
		dataType: 'json',
		timeout: 15000,
		success: function(data) {
		    layer.close(ii)
		    if(data.code == 200){
		        layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                }, function() {
                    location.reload();
                });
		    }else{
		        layer.msg(data.msg, {
                    icon: 2,
                    time: 3000
                });
		    }
		},
		error: function(data) {
            layer.close(ii);
            layer.msg('服务器错误');
        }
	});
}

function Add_dmfQr(){
    var beizhu               = $("#beizhu").val();
    var alipaydmf_appid      = $("#alipaydmf_appid").val();
    var alipaypublicdmf_key  = $("#alipaypublicdmf_key").val();
    var appprivatedmf_key    = $("#appprivatedmf_key").val();
    var ii = layer.load(5, {
		shade: [0.1, '#fff']
	});
	$.ajax({
	    type: "POST",
	    url: "Ajax.php",
	    data: {
	        act:'Add_dmfQr', 
	        beizhu:beizhu,
	        alipaydmf_appid:alipaydmf_appid,
	        alipaypublicdmf_key:alipaypublicdmf_key,
	        appprivatedmf_key:appprivatedmf_key
	     },
	    dataType: 'json',
	    timeout: 15000,
	    success: function(data) {
	       layer.close(ii)
	       if(data.code == 200){
	           layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                }, function() {
                    location.reload();
                });
	       }else{
	           layer.msg(data.msg, {
                    icon: 2,
                    time: 3000
                });
	       }
	    },
	    error: function(data) {
            layer.close(ii);
            layer.msg('服务器错误');
        }
	});
    
}
function Add_Qr(){
    var alipay   = $("#alipay").val();
    var beizhu   = $("#beizhu").val();
    var ii = layer.load(5, {
		shade: [0.1, '#fff']
	});
	$.ajax({
	    type: "POST",
	    url: "Ajax.php",
	    data:{
	        act:'Add_Qr',
	        alipay:alipay,
	        beizhu:beizhu
	    },
	    dataType: 'json',
	    timeout: 15000,
	   success: function(data) {
	       layer.close(ii)
	       if(data.code == 200){
	           layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                }, function() {
                    location.reload();
                });
	       }else{
	           layer.msg(data.msg, {
                    icon: 2,
                    time: 3000
                });
	       }
	   },
	   error: function(data) {
            layer.close(ii);
            layer.msg('服务器错误');
        }
	});
	
}

function GET_qq_QR(){
    var qqpay   = $("#qqpay").val();
    var beizhu   = $("#beizhu").val();
    var ii = layer.load(5, {
		shade: [0.1, '#fff']
	});
	$.ajax({
	    type: "POST",
	    url: "Ajax.php",
	    data:{
	        act:'Add_QQQr',
	        qqpay:qqpay,
	        beizhu:beizhu
	    },
	    dataType: 'json',
	    timeout: 15000,
	   success: function(data) {
	       layer.close(ii)
	       if(data.code == 200){
	           layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                }, function() {
                    location.reload();
                });
	       }else{
	           layer.msg(data.msg, {
                    icon: 2,
                    time: 3000
                });
	       }
	   },
	   error: function(data) {
            layer.close(ii);
            layer.msg('服务器错误');
        }
	});
}

function GET_wx_QR(){//店员上传
    var wxpay   = $("#wxpay").val();
    var qr_url  = $("#qr_url").val();
    var beizhu  = $("#beizhu").val();
    var wx_name = $("#wx_name").val();
    var ii = layer.load(5, {
		shade: [0.1, '#fff']
	});
	$.ajax({
	    type: "POST",
	    url: "Ajax.php",
	    data:{
	        act:'Add_wx_QR',
	        wxpay:wxpay,
	        qr_url:qr_url,
	        beizhu:beizhu,
	        wx_name:wx_name
	    },
	    dataType: 'json',
	    timeout: 15000,
	    success: function(data){
	        layer.close(ii)
	        if(data.code == 200){
	            layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                }, function() {
                    location.reload();
                });
	        }else{
	            layer.msg(data.msg, {
                    icon: 2,
                    time: 3000
                });
	        }
	    },
	    error: function(data) {
            layer.close(ii);
            layer.msg('服务器错误');
        }
	});
}

function GET_wx_macQR(){
    var mactype = $("#mactype").val();
    var qr_url  = $("#qr_url").val();
    var beizhu  = $("#beizhu").val();
    var macwxyunurl  = $("#macwxyunurl").val();
    var ii = layer.load(5, {
		shade: [0.1, '#fff']
	});
	$.ajax({
	    type: "POST",
	    url: "Ajax.php",
	    data:{
	       act:'Add_wx_MacQR',  
	       qr_url:qr_url,
	       beizhu:beizhu,
	       macwxyunurl:macwxyunurl,
	       mactype:mactype
	    },
	    dataType: 'json',
	    timeout: 15000,
	    success: function(data){
	        layer.close(ii)
	        if(data.code == 200){
	            layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                }, function() {
                    location.reload();
                });
	        }else{
	            layer.msg(data.msg, {
                    icon: 2,
                    time: 3000
                });
	        }
	    },
	    error: function(data) {
            layer.close(ii);
            layer.msg('服务器错误');
        }
	});
}

function GET_wx_WindowsQR(){
    var Windowstype = $("#Windowstype").val();
    var qr_url  = $("#qr_url").val();
    var beizhu  = $("#beizhu").val();
    var uoswxyunurl  = $("#uoswxyunurl").val();
    var ii = layer.load(5, {
		shade: [0.1, '#fff']
	});
	$.ajax({
	    type: "POST",
	    url: "Ajax.php",
	    data:{
	        act:'Add_wx_WindowsQR',  
	       qr_url:qr_url,
	       beizhu:beizhu,
	       uoswxyunurl:uoswxyunurl,
	       Windowstype:Windowstype
	    },
	    dataType: 'json',
	    timeout: 15000,
	    success: function(data){
	        layer.close(ii)
	        if(data.code == 200){
	            layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                }, function() {
                    location.reload();
                });
	        }else{
	            layer.msg(data.msg, {
                    icon: 2,
                    time: 3000
                });
	        }
	    },
	    error: function(data) {
            layer.close(ii);
            layer.msg('服务器错误');
        }
	});
}
function Upload(){
    var ii = layer.load(3, {
		shade: [0.1, '#fff']
	});
	var file = document.getElementById("imgfile").files[0];
	var formData = new FormData();
	formData.append('image_field', file);
	$.ajax({
	    url: "Ajax.php?act=Add_Upload",
	    type: "POST",
	    data: formData,
	    contentType: false,
	    processData: false,
	    mimeType: "multipart/form-data",
	    dataType: 'json',
	    success: function(res) {
	        layer.close(ii);
	        if (res.code == 200){
	            layer.msg(res.msg, {
                    icon: 1,
                    time: 1000
                });
                $('#qr_url').val(res.data.qrcode);
	        } else{
	            layer.msg(data.msg, {
                    icon: 2,
                    time: 3000
                });
	        }
	    },
	    error: function(data) {
	        layer.close(ii);
	        layer.msg('服务器错误');
	    }
	});
}

function Upload1(){
    var ii = layer.load(3, {
		shade: [0.1, '#fff']
	});
	var file = document.getElementById("imgfile").files[0];
	var formData = new FormData();
	formData.append('image_field', file);
	$.ajax({
	    url: "Ajax.php?act=Add_Upload1",
	    type: "POST",
	    data: formData,
	    contentType: false,
	    processData: false,
	    mimeType: "multipart/form-data",
	    dataType: 'json',
	    success: function(res) {
	        layer.close(ii);
	        if (res.code == 200){
	            layer.msg(res.msg, {
                    icon: 1,
                    time: 1000
                });
                $('#qr_url').val(res.data.qrcode);
	        } else{
	            layer.msg(data.msg, {
                    icon: 2,
                    time: 3000
                });
	        }
	    },
	    error: function(data) {
	        layer.close(ii);
	        layer.msg('服务器错误');
	    }
	});
}



function editSave(id){
    layer.open({
		type: 2,
		maxmin: true,
		title: '修改二维码',
		shade: 0.1,
		area: screen(),
		content: "Qrlist?my=edit&id="+id
	});
}

function screen() {
	if (typeof width !== 'number' || width === 0) {
		width = $(window).width() * 0.8;
	}
	if (typeof height !== 'number' || height === 0) {
		height = $(window).height() * 0.5;
	}
	return [width + 'px', height + 'px'];
}

function edit_Qr(){
	var id= $("#id").val(); 
	var beizhu = $("#beizhu").val();
	var status = $("#status").val();
	var nums = $("#nums").val();
	var stat = $("#stat").val();
	var ii = layer.load(3, {
		shade: [0.1, '#fff']
	});
	$.ajax({
	    type: "POST",
	    url: "Ajax.php",
	    data: {
	        act:'edit_qr',
	        id:id,
	        beizhu:beizhu,
	        status:status,
	        nums:nums,
	        stat:stat
	    },
	    dataType: 'json',
	    timeout: 15000,
	    success: function(data) {
	        layer.close(ii);
	         if (data.code == 200){
	             layer.msg(data.msg, {
                    icon: 1,
                    time: 1000
                }, function() {
                    // 关闭编辑窗口
                   window.parent.closeEditWindow();
                    location.reload();
                });
	         }else{
	             layer.msg(data.msg, {
                    icon: 2,
                    time: 3000
                });
	         }
	    },
        error: function(data) {
            layer.close(ii);
            layer.msg('操作失败,服务器错误');
        }
	});
}

function closeEditWindow() {
    layer.closeAll('iframe');
}